﻿namespace SourceCodeRepository.Web.Controllers.Home.Snippets
{
    using System.Web.Mvc;
    using Persistence.Repositories.Interfaces;

    /// <summary>
    /// Controller for the Show Code Snippets View
    /// </summary>
    public class ShowSnippetsController : BaseController
    {
        /// <summary>
        /// Gets or sets the code snippet repository.
        /// </summary>
        /// <value>The snippet repository.</value>
        protected ICodeSnippetRepository SnippetRepository { get; set;}

        /// <summary>
        /// Initializes a new instance of the <see cref="ShowSnippetsController"/> class.
        /// </summary>
        /// <param name="snippetRepository">The snippet repository.</param>
        public ShowSnippetsController(ICodeSnippetRepository snippetRepository)
        {
            this.SnippetRepository = snippetRepository;
        }

        /// <summary>
        /// Gets all code snippets.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <returns></returns>
        public ActionResult GetAllSnippets(int? pageNumber)
        {
            var snippets = this.SnippetRepository.GetAll(pageNumber);
            return this.View(snippets);
        }

        /// <summary>
        /// Shows the default view of the controller.
        /// </summary>
        /// <returns></returns>
        public override ActionResult ShowView()
        {
            return this.GetAllSnippets(0);
        }
    }
}
